﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;

namespace TopShooter
{
    /// <summary>
    /// A valuable item the player can collect.
    /// </summary>
    public class Shotfired
    {
        private int _currentTextureIndex;
        private Texture2D _texture;
        private Texture2D[] _textures;
        private Vector2 origin;

		  public float GunRotation;

        public readonly Color Color = Color.Yellow;

        // The Shotfired is animated from a base location along the Y axis.
        private Vector2 _baseOffset;

        public Scene Scene
        {
            get { return scene; }
        }
        Scene scene;

        public PlayerEntity Player;

        public Shotfired(Scene scene, PlayerEntity player, Vector2 offset)
        {
            this.scene = scene;
            this.Player = player;
            this._baseOffset = offset;

            LoadContent();
        }

        /// <summary>
        /// Loads the Shotfired _texture and collected sound.
        /// </summary>
        public void LoadContent()
        {
            _textures = new Texture2D[5];
            _currentTextureIndex = 0;
            _textures[0] = Scene.Content.Load<Texture2D>("Effects/Shot Fired/Shot Fired 1");
				_textures[1] = Scene.Content.Load<Texture2D>("Effects/Shot Fired/Shot Fired 2");
				_textures[2] = Scene.Content.Load<Texture2D>("Effects/Shot Fired/Shot Fired 3");
				_textures[3] = Scene.Content.Load<Texture2D>("Effects/Shot Fired/Shot Fired 4");
				_textures[4] = Scene.Content.Load<Texture2D>("Effects/Shot Fired/Shot Fired 5");

            _texture = _textures[0];
            origin = new Vector2(_texture.Width / 2.0f, _texture.Height / 2.0f);
        }

        public void SetNextTexture()
        {
            _currentTextureIndex++;
            if (_currentTextureIndex >= _textures.Length)
            {
                _currentTextureIndex = 0;
            }
            _texture = _textures[_currentTextureIndex];
        }
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Vector2 offset)
        {
			  Vector2 effectOffset = MathUtil.RotateVector(_baseOffset, GunRotation);
				spriteBatch.Draw(_texture, Player.Location + effectOffset + offset, null, Color, GunRotation, origin, 1.0f, SpriteEffects.None, 0.0f);
        }
    }
}
